<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>swoole-websocket测试</title>
</head>
<body>
<h1>swoole的websocket</h1>
<script>
    var wsUrl = "ws://swoole.lexunw.com:8812";
    var websocket = new WebSocket(wsUrl);

    //实例化对象onopen属性
    websocket.onopen = function (evt) {
        websocket.send("hello swoole");
        console.log("connected-swoole-success",evt);
    }

    //实例化 onmessage
    websocket.onmessage = function (evt) {
        console.log('ws-server-return-data',evt.data);
    }

    //实例化 onclose
    websocket.onclose = function (evt) {
        console.log('close');
    }

    //错误
    websocket.onerror = function (evt, e) {
        console.log("error:"+evt.data);
    }
</script>
</body>
</html>